package com.zhentao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.pojo.TRegister;
import com.zhentao.service.TRegisterService;
import com.zhentao.mapper.TRegisterMapper;
import com.zhentao.vo.RegisterQuery;
import org.springframework.stereotype.Service;

/**
* @author Lenovo
* @description 针对表【t_register】的数据库操作Service实现
* @createDate 2025-07-31 11:31:29
*/
@Service
public class TRegisterServiceImpl extends ServiceImpl<TRegisterMapper, TRegister>
    implements TRegisterService{
    @Override
    public IPage<TRegister> getUserPage(RegisterQuery queryVO, int pageNum, int pageSize) {
        // 创建分页对象
        Page<TRegister> page = new Page<>(pageNum, pageSize);

        // 创建查询条件构造器
        QueryWrapper<TRegister> queryWrapper = new QueryWrapper<>();

        // 动态添加查询条件
        if (queryVO != null) {
            // 用户名模糊查询
            if (queryVO.getUname() != null && !queryVO.getUname().isEmpty()) {
                queryWrapper.like("username", queryVO.getUname());
            }
            if(queryVO.getIdNumber() != null && !queryVO.getIdNumber().isEmpty()){
                queryWrapper.like("id_number", queryVO.getIdNumber());
            }

            // 年龄范围查询
            if (queryVO.getStartTime() != null) {
                queryWrapper.ge("yy_time", queryVO.getStartTime());
            }
            if (queryVO.getEndTime() != null) {
                queryWrapper.le("yy_time", queryVO.getEndTime());
            }

            // 状态精确查询
            if (queryVO.getStatus() != null) {
                queryWrapper.eq("status", queryVO.getStatus());
            }
        }

        // 执行分页查询
        return baseMapper.selectPage(page, queryWrapper);
    }


}




